<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%@taglib
	uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page language="java" import="java.util.*" %>
<%@ page language="java" import="java.text.*" %>
<%@ page language="java" import="com.kook.ball.util.SendMail;" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">

<title>Check Verify</title>
</head>
<body>
<%
/*Date endDate=new Date();
long Enddate=endDate.getTime();
String initialDate = request.getParameter("StartDate");
Date StartDate;
	//try {
		StartDate = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss", Locale.US).parse(initialDate);
		long start=StartDate.getTime();
		out.print(start);
		//} catch (ParseException e) {
		// TODO Auto-generated catch block
		//e.printStackTrace();
		//}
//int accessDate=(int)(Enddate-StartDate.getTime())*(1000*60*60);
int accessDate=(int)(Enddate-start)*(1000*60*60);
out.print(accessDate);*/
boolean loginflag = true;
String Flag="Y";

String username=(String) session.getAttribute("username"); 
String VerifyCode=(String) session.getAttribute("VerifyCode"); 
String ReferenceCode=(String) session.getAttribute("ReferenceCode"); 
Date Starttime=(Date)session.getAttribute("Startdate");
Date end=new Date();
long finish=end.getTime()-Starttime.getTime();
int total=(int)(finish/60000);
Properties props = new Properties();
props.load(SendMail.class.getClassLoader().getResourceAsStream("pros.properties"));
String timeout=props.getProperty("timeout");
//int total=1;
//out.print(total);
//out.println(Starttime.getTime()+" end :"+end.getTime()+" finish :"+finish+" mins");
 %>

<c:set var="totaltime" scope="session" value="<%=total%>"/>
<c:set var="timeout" scope="session" value="<%=timeout%>"/>
<c:set var="VerifyCode" scope="session" value="<%=VerifyCode %>"/>
<c:set var="username" scope="session" value="<%=username %>"/>
<c:set var="ReferenceCode" scope="session" value="<%=ReferenceCode %>"/>
<c:set var="count" value="${count + 1}" scope="session"/>

<c:if test="${totaltime<timeout}">

<c:if test="${VerifyCode!=param.passcode && count<3 }">


<form method="post" action="OTP.jsp">
<c:import url="header.jsp"></c:import>
<br>
<br>

<input type="hidden" name="Flag" value="<%=Flag%>">
<br>
<div class="hero-unit">
<h1>Failure</h1>
<p>OTP Wrong!!
<c:out value="${count}"></c:out>
Time(s), Please Try Again </p>
</div><br>
 <input type="submit" value="Request" name="submit">	
</form>
</c:if>
<sql:setDataSource dataSource="jdbc/security" var="security" />
<c:if test="${VerifyCode==param.passcode && count<3 }">
		<sql:update var="count" dataSource="${security}">
		INSERT INTO OTPSuccess VALUES ('${username}', '${VerifyCode}', '${ReferenceCode}')
		</sql:update>
		<c:redirect url="/Success.html"></c:redirect>
</c:if>

<c:if test="${count>2 }">
<form method="post" action="RequestOTP.jsp">
<c:import url="header.jsp"></c:import>
<br>
<br>

<br>
<div class="hero-unit">
<h1>Failure</h1>
<p>YOU TRY TO VERIFY OTP OVER 3 Times !! , Please Request OTP  Again</p>
</div><br>
 <input type="submit" value="Request" name="submit">	
</form>
</c:if>
</c:if>

<c:if test="${totaltime>timeout}">
<form method="post" action="RequestOTP.jsp">
<c:import url="header.jsp"></c:import>
<br>
<br>

<br>
<div class="hero-unit">
<h1>Failure</h1>
<p>OTP EXPIRED !! , Please Request OTP Again</p>
</div><br>
 <input type="submit" value="Request" name="submit">	
</form>
</c:if>
 
</body>
</html>